package com.pig.provide.http;

import com.pig.provide.netty.server.TextServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.*;

/**
 * @author lizhiwei
 */
@Component
@Slf4j
public class Boot {
    @Autowired
    ApplicationContext applicationContext;
    private static ExecutorService executorNettyThread = Executors.newFixedThreadPool(20);

    @PostConstruct
    public void startNetty() {
        executorNettyThread.submit(() -> {
            TextServer textServer = applicationContext.getBean(TextServer.class);
            try {
                textServer.start();
                log.error("start netty provide success!");
            } catch (Exception e) {
                log.error("start netty provide error!");
            }
        });
    }
}
